/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ants;
import javax.swing.*;
import java.awt.*;
import java.util.HashMap;
/**
 *
 * @author Lnx
 */
public class FTablero extends JPanel{
    Mapa m;
    boolean activated = false;
    boolean t;
    int pheromone;
    int tilesize;
    int w, h;
    HashMap trans;
    public FTablero(Mapa map, int f, boolean t, int tz){
        trans = new HashMap<Integer, String>();
        trans.put(0,"←↑");
        trans.put(3,"↑");
        trans.put(6,"↑→");
        trans.put(1,"←");
        trans.put(4,"O");
        trans.put(7,"→");
        trans.put(2,"←↓");
        trans.put(5,"↓");
        trans.put(8,"↓→");
        m = map;
        pheromone = f;
        this.t = t;
        tilesize = this.getHeight()/(map.h + 2);
    }
    
    public void getMap(Mapa map){
        //System.out.println("le pintando");
        m = map;
        if(activated == false)
            activated = true;
        repaint();
        //this.paint(this.getGraphics());
    }
    @Override public void paintComponent(Graphics g) {
        tilesize = this.getHeight()/(m.h + 2);
        super.paintComponent(g);
        if(activated == true){
        Image buffer = createImage(this.getSize().width, this.getSize().height);
        Graphics g2 = buffer.getGraphics();
        //g2.setColor(Color.black);
        //System.out.println("HUEHUEHUE");
        if (t == true){
            for(int i = 0; i < m.cells.length; i++){
                for(int j = 0; j < m.cells[0].length; j++){
                    if(m.cells[i][j].tipo == Constantes.obstaculo){
                        g2.setColor(Color.gray);
                        //g2.fillRect(j+(j*tilesize), i+(i*tilesize), tilesize, tilesize);
                    }
                    else{
                        int ph;
                        //System.out.println("Fermona: " + m.cells[i][j].getPheromone(0));
                        switch(pheromone){
                            case 0:
                                ph = (m.cells[i][j].getPheromone(0)*255);
                                g2.setColor(new Color(0, 0 ,ph));
                                break;
                            //case 0: g2.setColor(new Color(255, 0 ,0));break;
                            case 1:
                                ph = (m.cells[i][j].getPheromone(1)*255)/Constantes.maxfer;
                                g2.setColor(new Color(0,ph,0));
                                break;
                            //case 1: g2.setColor(new Color(0,255,0));break;
                        }
                    }
                    g2.fillRect(j+(j*tilesize), i+(i*tilesize), tilesize, tilesize);
                }
            }
        }
        else{
            for(int i = 0; i < m.cells.length; i++){
                for(int j = 0; j < m.cells[0].length; j++){
                    g2.drawString(trans.get(m.cells[i][j].getDir())+":"+ m.cells[i][j].getDist(), j+(j*tilesize), i+(i*tilesize));
                }
            }
        }
        g.drawImage(buffer, 0, 0, this);
        }
    }
    /*
    
    public void paint(Graphics g){
        
    }*/
}
